package thread;

public class DaemonThreadDemo {
    //守护线程和用户线程是两类,不是守护某个单一线程
    //进程只要发现所有守护线程都结束了,就会结束自身,在此之前会杀死所有还在运行的守护线程
    public static void main(String[] args)  {
        Thread rose = new Thread("rose") {
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(getName() + ":let me go!");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(getName() + ":Ahahahaa");
                System.out.println("扑通");
            }
        };

        Thread jack =new Thread("jack"){
            public void run(){
                while(true){
                    System.out.println(getName()+":you jump!I jump!");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        };

        rose.start();
        jack.setDaemon(true);//将jack设置为守护线程
        jack.start();

        //while(true);


    }
}